﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TPAMainReportTools
{
    public class InputBox : System.Windows.Forms.Form       //InputBox类
    {
        private System.Windows.Forms.Label lblInfo;
        private System.Windows.Forms.TextBox txtData;
        private System.Windows.Forms.Button btnSure;
        private System.Windows.Forms.Button btnCancel;
        private bool _Cancel = false;

        private System.ComponentModel.Container components = null;

        private InputBox()
        {
            InitializeComponent();
        }

        public bool Cancel
        {
            set
            {
                _Cancel = value;
            }
            get
            {
                return _Cancel;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }

            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.lblInfo = new System.Windows.Forms.Label();
            this.txtData = new System.Windows.Forms.TextBox();
            this.btnSure = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // lblInfo
            // 
            this.lblInfo.AutoSize = true;
            this.lblInfo.Location = new System.Drawing.Point(30, 24);
            this.lblInfo.Name = "lblInfo";
            this.lblInfo.Size = new System.Drawing.Size(41, 12);
            this.lblInfo.TabIndex = 0;
            this.lblInfo.Text = "lblInfo";
            // 
            // txtData
            // 
            this.txtData.Location = new System.Drawing.Point(21, 49);
            this.txtData.Name = "txtData";
            this.txtData.Size = new System.Drawing.Size(321, 21);
            this.txtData.TabIndex = 1;
            // 
            // btnSure
            // 
            this.btnSure.Location = new System.Drawing.Point(164, 87);
            this.btnSure.Name = "btnSure";
            this.btnSure.Size = new System.Drawing.Size(75, 25);
            this.btnSure.TabIndex = 2;
            this.btnSure.Text = "确  定";
            this.btnSure.UseVisualStyleBackColor = true;
            this.btnSure.Click +=new EventHandler(btnSure_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Location = new System.Drawing.Point(267, 87);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 25);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "取  消";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel .Click +=new EventHandler(btnCancel_Click);
            // 
            // InputBox
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(354, 125);
            this.Controls.Add(this.btnSure);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.txtData);
            this.Controls.Add(this.lblInfo);
            this.Name = "InputBox";
            this.Text = "InputBox";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        //对键盘进行响应
        private void txtData_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
            {
                this.Close();
            }

            else if (e.KeyCode == System.Windows.Forms.Keys.Escape)
            {
                txtData.Text = string.Empty;
                this.Close();
            }

        }

        //显示InputBox
        public static string ShowInputBox(string Title, string keyInfo)
        {
            InputBox inputbox = new InputBox();
            inputbox.Text = Title;
            if (keyInfo.Trim() != string.Empty)
                inputbox.lblInfo.Text = keyInfo;
            inputbox.ShowDialog();

            return inputbox.txtData.Text;
        }

        public static string ShowInputBox(string Title, string keyInfo,string strDefaultValue)
        {
            InputBox inputbox = new InputBox();
            inputbox.Text = Title;
            inputbox.txtData.Text = strDefaultValue;
            if (keyInfo.Trim() != string.Empty)
                inputbox.lblInfo.Text = keyInfo;
            inputbox.ShowDialog();

            return inputbox.txtData.Text;
        }

        private void btnSure_Click(Object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(Object sender, EventArgs e)
        {
            this.txtData.Text  = string.Empty;
            Cancel = true;
            this.Close();
        }
    }
}
